from flask import current_app as app
from flask import Blueprint,request
from utils.myfile import myfile
import os
from xlrd import open_workbook

bp_company=Blueprint("company",__name__)


@bp_company.route("/test")
def test():
    str="请求ip:"+request.remote_addr+",请求的url"+request.url+"错误信息"+"\n"
    app.logger.error(str)
    return "hell21312312"

#上传excel，并导入数据库
@bp_company.route("/upload",methods=["POST"])
def method_name():
    #获取文件
    file=request.files['file']
    newname=myfile.rename(file.filename)
    #上传文件
    file.save(os.path.join("./static/files/"+newname))
    #打开文件读取
    name = './static/files/'+newname
    bk = open_workbook(name, encoding_override='utf-8')
    sh = bk.sheets()[0]
    nrows = sh.nrows
    ncols = sh.ncols
    for i in range(1, nrows):
        row_date = sh.row_values(i)
        print(row_date[0])
        print(row_date[1])
    return 'ok'
    #封装数据写入数据库
